package pro.cherish.helloworld.server;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.Delimiters;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
/**
 * @author 创建人：lys
 * @version 版本号：V1.0
 * <p>
 * ***************************修订记录************************************
 * 2020-6-15 lys 创建该类功能。
 * **********************************************************************
 * </p>
 * @ClassName 类名：ServerInitializer
 * @Description 功能说明：
 * <p>
 * TODO
 * </p>
 * **********************************************************************
 * @date 创建日期： 2020-6-15 
 */
public class ServerInitializer extends ChannelInitializer<SocketChannel> {

	private static final StringDecoder DECODER=new StringDecoder();
	private static final StringEncoder ENCODER =new StringEncoder();
	private static final ServerHandler SERVER_HANDLER = new ServerHandler();
	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		ChannelPipeline pipeline = ch.pipeline();
		// add the text line codec combination first
		pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
		// the encoder and decoder are static as these are sharable   添加字符串解密器和编码器
		pipeline.addLast(DECODER);
		pipeline.addLast(ENCODER);
		// and then business logic. 业务逻辑
		pipeline.addLast(SERVER_HANDLER);
	}
}
